#include"Block.h"
#include"Chunk.h"

namespace Craft
{
	bool Block::intersection(const glm::vec3& orgin, const glm::vec3& dir, HitInfo& hitInfo)
	{
		AABB box(get_pos(), 1.0f);

		if (box.intersect_Ray(orgin,dir,hitInfo) )
		{
			return true;
		}

		return false;
	}


	const uint32_t Block::get_Id()const
	{
		return m_Id;
	}

	void Block::set_Id(const GLuint& id)
	{
		m_Id = id;
	}

	const GLfloat Block::get_size()const
	{
		return m_size;
	}

	const glm::vec3 Block::get_pos()const
	{
		return m_pos;
	}

	const glm::vec3 Block::get_lb_pos()const
	{
		return glm::vec3(m_pos.x + m_size *.5, m_pos.y + m_size *.5, m_pos.z + m_size *.5);
	}

	void Block::set_pos(const glm::vec3& pos)
	{
		m_pos = pos;
	}

	void Block::set_type(const GLuint& t)
	{
		m_type = t;
	}

	void Block::set_lightValue(const GLuint value)
	{
		m_lightValue = value;
	}

	const GLuint Block::get_lightValue()const
	{
		return m_lightValue;
	}

	const GLuint Block::get_lightOpacity()const
	{
		return m_lightOpacity;
	}


	const uint32_t Block::get_type()const
	{
		return m_type;
	}

	AABB Block::get_BoundingBox()
	{
		return AABB(get_world_pos(), m_size);
	}

	Chunk* Block::get_chunk()
	{
		return m_chunk;
	}

	void Block::set_chunk(Chunk* chunk)
	{
		m_chunk = chunk;
	}


	const glm::vec3 Block::get_world_pos()const
	{
		if (m_chunk != nullptr)
		{
			return m_chunk->get_pos() + m_pos;
		}

		return m_pos;
	}

}